package com.tgh.au.c5;

import java.util.concurrent.TimeUnit;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.Rect;
import android.graphics.RectF;
import android.view.View;

public class GameView2 extends View implements Runnable {
	private Paint paint;
	private GameView3 gameView3;
	public GameView2(Context context) {
		super(context);
		paint=new Paint();
		gameView3=new GameView3(context);
		new Thread(this).start();
	}
	@Override
	public void run() {
		while (!Thread.currentThread().isInterrupted()) {
			try {
				TimeUnit.MILLISECONDS.sleep(100);
			} catch (InterruptedException e) {
				Thread.currentThread().interrupt();
			}
			postInvalidate();
		}
	}
	@Override
	protected void onDraw(Canvas canvas) {
		canvas.drawColor(Color.BLACK);
		paint.setAntiAlias(true);
		paint.setStyle(Paint.Style.STROKE);
		
		
		//canvas.clipRect(10, 10, 280, 260);
		canvas.save();
		canvas.rotate(45.0f);
		paint.setColor(Color.RED);
		canvas.drawRect(new Rect(15, 15, 140, 70), paint);
		canvas.restore();
		paint.setColor(Color.GREEN);
		canvas.drawRect(new Rect(150, 75, 260, 120), paint);
		
		paint.setColor(Color.LTGRAY);
		canvas.drawOval(new RectF(80, 30, 120, 70), paint);
		
		paint.setColor(Color.GRAY);
		Path path1=new Path();
		path1.moveTo(150+5, 80-50);
		path1.lineTo(150+45, 80-50);
		path1.lineTo(150+30, 120-50);
		path1.lineTo(150+20, 120-50);
		path1.close();
		canvas.drawPath(path1, paint);
		
		paint.setColor(Color.RED);
		paint.setStrokeWidth(3);
		canvas.drawLine(5, 110, 315, 110, paint);
		gameView3.drawShape(canvas);
	}
	
}
